import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddSuccess from '@/pages/AddSuccess'
import ShopCart from '@/pages/Cart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
// 二级路由组件
import myOrder from "@/pages/Center/myOrder";
// import groupOrder from "@/pages/Center/groupOrder";

// 路由懒加载 使用时采引入
const foo = () => {
    return import('@/pages/Center/groupOrder')
}

export default [
    {
        path: '*',
        redirect: '/home'
    },
    {
        path: '/home',
        component: Home,
        meta: { isShow: true }
    },
    {
        path: '/search/:keyword?',
        component: Search,
        meta: { isShow: true },
        name: 'search'
    },
    {
        path: '/detail/:skuId',
        component: Detail,
    },
    {

        path: '/addsuccess',
        name: 'addsuccess',
        component: AddSuccess,
        meta: { isShow: true },
    },
    {
        path: '/shopcart',
        name: 'shopcart',
        component: ShopCart,
    },
    {
        path: '/trade',
        component: Trade,
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            //  trade页面必须在购物车页面之后
            if (from.path == '/shopcart') {
                next()
            } else {
                // 不是从购物车页面来的，中断当前导航
                // 浏览器url改变时，url会重置到 from路由 对应的地址
                next(false)
            }
        }
    },
    {
        path: '/pay',
        component: Pay,
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next();
            } else {
                next(false);
            }
        }
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
    },
    {
        path: '/center',
        component: Center,
        children: [
            {
                path: 'myorder',
                // 路由懒加载 简写
                component: () => import("@/pages/Center/myOrder")
            },
            {
                path: 'grouporder',
                // 路由懒加载
                component: foo,
            },
            {
                path: '/center',
                component: myOrder,
            },
        ]
    },
    {
        path: '/login',
        component: Login,
        meta: { isShow: false },
    },
    {
        path: '/register',
        component: Register,
        meta: { isShow: false }
    },

]
